package com.example.xpvideo.service.serviceImpl;

import com.example.xpvideo.service.FileService;
import com.example.xpvideo.tools.OssUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MaxUploadSizeExceededException;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author hjt
 * @create 2021-08-28 14:39
 * @describe：
 */
@Service
public class FileServiceImpl implements FileService {

    @Autowired
    private OssUtils ossUtils;


    /**
     * 添加图片
     * @param file
     * @return
     */
    @Override
    public String addImages(MultipartFile file) {
        String url = "";
        try {
            url = ossUtils.uploadFileAvatar(file,"images");
        } catch (MaxUploadSizeExceededException e) {
            e.printStackTrace();
        }
        return url;
    }

    @Override
    public boolean delImages(String imagesUrl) {
        try {
            ossUtils.delFile(imagesUrl);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }

}
